package ch02.demo;


import org.dom4j.Document;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.w3c.dom.Document;

import java.io.File;
import java.util.Iterator;

public class demo7 {
    public static void main(String[] args) {
        Document doc = null;
        try {
            SAXReader saxReader = new SAXReader();
            doc =saxReader.read(new File("src/ch02/demo/demo.xml"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        Element root = doc.getRootElement();
        for (Iterator itBrand=root.elementIterator();itBrand.hasNext();){
            Element brand =(Element)itBrand.next();
            System.out.println("品牌："+brand.attributeValue("name"));
            for (Iterator itera=brand.elementIterator();itera.hasNext();){
                Element type=(Element) itera.next();
                System.out.println("型号"+type.attributeValue("name"));
            }
        }
    }
}
